package com.millstein.controller;

import com.millstein.request.LockCouponRequest;
import com.millstein.service.CouponRecordService;
import com.millstein.util.JsonData;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author millstein
 * @since 2021-09-14
 */
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {

    @Autowired
    private CouponRecordService couponRecordService;

    @GetMapping("page_coupon_record")
    @ApiOperation("分页查询领券记录")
    public JsonData pageCouponRecord(@ApiParam("当前页") @RequestParam(value = "page", defaultValue = "1") int page,
                                     @ApiParam("每页记录数") @RequestParam(value = "size", defaultValue = "10") int size) {
        return JsonData.buildSuccess(couponRecordService.pageCouponRecord(page, size));
    }

    @GetMapping("/{coupon_record_id}")
    @ApiOperation("根据id查询领券记录")
    public JsonData findCouponRecord(@ApiParam("领券记录id") @PathVariable("coupon_record_id") Long couponRecordId) {
        return JsonData.buildSuccess(couponRecordService.findCouponRecord(couponRecordId));
    }

    @PostMapping("lock_coupon")
    @ApiOperation("rpc调用-锁定优惠券")
    public JsonData lockCoupon(@ApiParam("锁定优惠券需要的信息") @RequestBody LockCouponRequest lockCouponRequest) {
        couponRecordService.lockCoupon(lockCouponRequest);
        return JsonData.buildSuccess();
    }
}

